import React from "react";
import { Routes, Route, StaticRouter } from "react-router-dom";
import Home from "./pages/Home";
import About from "./pages/About";
import UserInfo from "./pages/UserInfo";
import {
  InitialStateContext,
  InitialStateDataType,
} from "./context/InitialStateContext";

export function getServerApp(url: string, initialState?: InitialStateDataType): React.ReactNode {
  return (
    <StaticRouter location={url} basename="/website">
      <App initialState={initialState} />
    </StaticRouter>
  );
}

type Props = {
  initialState?: InitialStateDataType;
};

const App: React.FC<Props> = (props: Props) => {
  return (
    <div suppressHydrationWarning={true}>
      <InitialStateContext.Provider value={props.initialState || {}}>
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/user" element={<UserInfo />} />
        </Routes>
      </InitialStateContext.Provider>
    </div>
  );
};

export default App;
